package com.flash.BusinessParameters.controller;

import com.flash.BusinessParameters.entity.Broker;
import com.flash.BusinessParameters.entity.ExchangeRate;
import com.flash.BusinessParameters.mapper.ExchangeRateMapper;
import com.flash.BusinessParameters.service.ExchangeRateService;
import com.flash.GlobalManagement.util.Dbutil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class ExchangeRateController {

    @Resource
    Dbutil dbutil;

    @Resource
    ExchangeRateService exchangeRateService;
    @RequestMapping("/toExchangeRate")
    public String toExchangeRate(){
        return "exchangeRate";
    }
    @RequestMapping("/selectExchangeRate")
    @ResponseBody
    //查询全部
    public Map selectExchangeRate(){
        System.out.println("查询全部");
        HashMap map=new HashMap();
        List<ExchangeRate> exchangeRateList = exchangeRateService.selectExchangeRate();
        int i = exchangeRateService.selectCountExchangeRate();
        System.out.println(exchangeRateList);
        map.put("code",0);
        map.put("msg","");
        map.put("data",exchangeRateList);
        map.put("count",i);
        return map;
    }
    @RequestMapping("/selectExchangeRateMap")
    @ResponseBody
    //按条件查询全部
    public Map selectExchangeRateMap(Integer exchangeName, int page, int limit){
        System.out.println("按条件");
        HashMap map=new HashMap();
        if (exchangeName==null) {
            exchangeName=0;
        }

        List<ExchangeRate> exchangeRateList = exchangeRateService.selectExchangeRateMap(exchangeName, page, limit);
        int i = exchangeRateService.selectCountExchangeRate();
        map.put("code",0);
        map.put("msg","");
        map.put("data",exchangeRateList);
        map.put("count",i);
        return map;
    }
    @RequestMapping("/selectExchangeRateMap2")
    @ResponseBody
    //查询债券或者股票
    public Map selectExchangeRateMap2(int exchangeType){
        System.out.println("按条件222222:,," + exchangeType);
        HashMap map=new HashMap();

        List<ExchangeRate> exchangeRateList = exchangeRateService.selectExchangeRateMap2(exchangeType);
        int i = exchangeRateService.selectCountExchangeRate();
        map.put("code",0);
        map.put("msg","");
        map.put("data",exchangeRateList);
        map.put("count",i);
        return map;
    }
    @RequestMapping("/insertExchangeRate")
    @ResponseBody
    //添加
    public String insertExchangeRate(ExchangeRate exchangeRate){
        System.out.println("添加用户");
        int i = exchangeRateService.insertExchangeRate(exchangeRate);
        System.out.println(i);
        if (i>0){
            return "ok";
        }else{
            return "no";
        }
    }

    @RequestMapping("/deleteExchangeRate")
    @ResponseBody
    //删除
    public int deleteExchangeRate(int exchangeName){
        System.out.println("删除");
        int i = exchangeRateService.deleteExchangeRate(exchangeName);
        System.out.println(i);
        return i;
    }
    @RequestMapping("/upExchangeRate")
    @ResponseBody
    //修改
    public int updateExchangeRate(ExchangeRate exchangeRate){
        System.out.println("这是修改");
        int i = exchangeRateService.updateExchangeRate(exchangeRate);
        System.out.println(i);
        return i;
    }
}
